package com.headFirstModel.observerPattern.jdk;

import java.util.Observable;

/**
 * 利用JDK自带观察者模式实现 气象发布
 * Observable:被观察者
 */
public class WeatherData extends Observable{
    private float temperature; //温度
    private float humidity; //湿度
    private float pressure; //气压

    /**
     * 设置气象信息
     */
    public void setMeasurements(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }
    public float getTemperature() {
        return temperature;
    }
    public float getHumidity() {
        return humidity;
    }
    public float getPressure() {
        return pressure;
    }

    public void measurementsChanged(){
        //当从气象站得到更新观测值时，我们通知观察者。
        setChanged();
        notifyObservers();
    }
}
